package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppFunctionConfiguration;
import com.ruoyi.system.service.IAppFunctionConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 功能配置Controller
 *
 * @author ruoyi
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/system/configuration")
public class AppFunctionConfigurationController extends BaseController {
    @Autowired
    private IAppFunctionConfigurationService appFunctionConfigurationService;

    /**
     * 查询功能配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppFunctionConfiguration appFunctionConfiguration) {
        startPage();
        List<AppFunctionConfiguration> list = appFunctionConfigurationService.selectAppFunctionConfigurationList(appFunctionConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出功能配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:export')")
    @Log(title = "功能配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppFunctionConfiguration appFunctionConfiguration) {
        List<AppFunctionConfiguration> list = appFunctionConfigurationService.selectAppFunctionConfigurationList(appFunctionConfiguration);
        ExcelUtil<AppFunctionConfiguration> util = new ExcelUtil<AppFunctionConfiguration>(AppFunctionConfiguration.class);
        util.exportExcel(response, list, "功能配置数据");
    }

    /**
     * 获取功能配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/getOne")
    public AjaxResult getInfo() {
        AppFunctionConfiguration info = appFunctionConfigurationService.selectAppFunctionConfigurationById(10001L);
        if (info != null) {
            if (info.getBlacklistState() == 0) {
                info.setBlacklistStateEnBle(true);
            } else {
                info.setBlacklistStateEnBle(false);
            }
            if (info.getAddFriendState() == 0) {
                info.setAddFriendStateEnBle(true);
            } else {
                info.setAddFriendStateEnBle(false);
            }
            if (info.getAddGroupState() == 0) {
                info.setAddGroupStateEnBle(true);
            } else {
                info.setAddGroupStateEnBle(false);
            }
            if (info.getWelcomeState() == 0) {
                info.setWelcomeStateEnBle(true);
            } else {
                info.setWelcomeStateEnBle(false);
            }
            if (info.getDynamicState() == 0) {
                info.setDynamicStateEnBle(true);
            } else {
                info.setDynamicStateEnBle(false);
            }
            if (info.getGroupPicState() == 0) {
                info.setGroupPicStateEnBle(true);
            } else {
                info.setGroupPicStateEnBle(false);
            }
            if (info.getGroupVideoState() == 0) {
                info.setGroupVideoStateEnBle(true);
            } else {
                info.setGroupVideoStateEnBle(false);
            }
            if (info.getGroupMapState() == 0) {
                info.setGroupMapStateEnBle(true);
            } else {
                info.setGroupMapStateEnBle(false);
            }
            if (info.getVoiceState() == 0) {
                info.setVoiceStateEnBle(true);
            } else {
                info.setVoiceStateEnBle(false);
            }
            if (info.getInvitationCodeState() == 0) {
                info.setInvitationCodeStateEnBle(true);
            } else {
                info.setInvitationCodeStateEnBle(false);
            }
        }
        return success(info);
    }

    /**
     * 新增功能配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "功能配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppFunctionConfiguration appFunctionConfiguration) {
        return toAjax(appFunctionConfigurationService.insertAppFunctionConfiguration(appFunctionConfiguration));
    }

    /**
     * 修改功能配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "功能配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppFunctionConfiguration appFunctionConfiguration) {
        return toAjax(appFunctionConfigurationService.updateAppFunctionConfiguration(appFunctionConfiguration));
    }

    /**
     * 删除功能配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "功能配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appFunctionConfigurationService.deleteAppFunctionConfigurationByIds(ids));
    }
}
